package com.zzty.txj.serviceImpl;

import com.zzty.txj.dao.DoDailyMapper;
import com.zzty.txj.entity.DoDaily;
import com.zzty.txj.service.DoDailyService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoDailyServiceImpl implements DoDailyService {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DoDailyServiceImpl.class);

    @Autowired
    DoDailyMapper doDailyMapper;

    @Override
    public List getRecordByDateAndId(DoDaily doDaily) {
        List<DoDaily> records = doDailyMapper.getRecordByDateAndId(doDaily);
        if (records == null || records.isEmpty()) {
            return null;
        } else {
            return records;
        }
    }

    @Override
    public Integer updateRecordById(DoDaily doDaily) {
        Integer count = doDailyMapper.updateRecordById(doDaily);
        if (count == 1) {
            return count;
        } else {
            return 0;
        }
    }

    @Override
    public DoDaily getDoDailyById(Integer id) {
        DoDaily doDaily = doDailyMapper.getDoDailyById(id);
        if (doDaily != null) {
            return doDaily;
        } else {
            return null;
        }
    }

    @Override
    public List<DoDaily> getDoDailyByDateAndUser(DoDaily doDaily) {
        List<DoDaily> records = doDailyMapper.getRecordByDateAndId(doDaily);
        if (records == null || records.isEmpty()) {
            return null;
        } else {
            return records;
        }
    }

    @Override
    public List<DoDaily> getDoDailyByUserId(Integer userId) {
        List<DoDaily> doDailies = doDailyMapper.getDoDailyByUserId(userId);
        if (doDailies == null || doDailies.isEmpty()) {
            return null;
        }else {
            logger.info("getDoDailyByUserId doDailies: " + doDailies.get(0).toString());

            return doDailies;
        }
    }


}
